
local AssetBundleManager = LunLua.AssetBundleManager.Instance

local AssetManager = require("unity.AssetManager")
local LuaApplication = require("unity.LuaApplication")

local UpdateScene = class("UpdateScene", require("unity.LuaMonoBehaviour"))

---
--- Progress Message UpdateURL GameScene
---
function UpdateScene:Awake()
    self.mContinueGame = false
end

function UpdateScene:Start()
    self.Progress.fillAmount = 0
    self.Message.text = "检查更新..."

    coroutine.start(function() 
        local result = AssetManager:CheckUpdateAsync(self.UpdateURL)
        if result then
            self.Message.text = "更新中..."
            result = AssetManager:UpdateAssetsAsync(function(progress)
                self.Progress.fillAmount = progress
            end, function(message)
                
            end)
            if result then
                LuaApplication:Restart()
            else
                self.Progress.fillAmount = 1
                self.Message.text = "更新出错！"
            end
        else
            self.Progress.fillAmount = 1
            self.Message.text = "点击任意位置继续..."
            self.mContinueGame = true
        end
    end)
end

function UpdateScene:OnClickContinue()
    if self.mContinueGame then
        self.Message.text = "游戏加载中..."
        self.mContinueGame = false
        coroutine.start(function() 
            AssetManager:LoadSceneAsync(self.GameScene)
        end)
    end
end

return UpdateScene
